package binaryTree;

/**
 * @className: LeetCode_108
 * @Description: ...
 * @author: kunkun
 * @date: 2025/3/24 22:44
 */
public class LeetCode_108 {

    public class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;
        TreeNode() {}
        TreeNode(int val) { this.val = val; }
        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }

    public TreeNode sortedArrayToBST(int[] nums) {
        return solution_1(nums,0,nums.length-1);
    }

    public TreeNode solution_1(int[] nums,int start,int end){
        //1. 终止条件返回
        if (start>end){
            return null;
        }

        //2. 递归体
        int index = (start+end)/2;
        TreeNode node = new TreeNode(nums[index]);
        node.left = solution_1(nums,start,index-1);
        node.right = solution_1(nums,index+1,end);
        return node;


    }





}
